import request from '../utils/request'

// 获取文章详情的API
// 形参是文章的ID
export const getArticleAPI = function (id) {
  return request.get('/v1_0/articles/' + id)
}

// 关注作者的API接口
export const followUserAPI = function (target) {
  return request.post('/v1_0/user/followings', {
    target
  })
}

// 取消关注用户的 API
export const unfollowUserAPI = userId => {
  return request.delete(`/v1_0/user/followings/${userId}`)
}

// 点赞的API
export const addLikeAPI = function (artId) {
  return request.post('/v1_0/article/likings', {
    target: artId
  })
}

// 取消点赞的 API（形参中的 artId 是文章的 Id）
// export const delLikeAPI = artId => {
//   return request.delete(`/v1_0/article/likings/${artId}`)
// }
export const delLikeAPI = function (id) {
  return request.delete('/v1_0/article/likings/' + id)
}

// 获取评论列表的API接口
export const getCmtListAPI = function (artId, offset) {
  return request.get('/v1_0/comments', {
    params: {
      type: 'a',
      source: artId,
      offset
    }
  })
}

// 评论点赞的 API
export const addLikeCmtAPI = cmtId => {
  return request.post('/v1_0/comment/likings', {
    target: cmtId
  })
}

// 取消点赞的API
export const delLikeCmtAPI = function (cmtId) {
  return request.delete('/v1_0/article/likings/' + cmtId)
}

// 发表评论的API
export const pubCommAPI = function (artId, content) {
  return request.post('/v1_0/comments', {
    target: artId,
    content
  })
}
